package com.hh.demo_ui;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.hh.adapters.CDTListAdapter;
import com.hh.clientdatatable.ClientDataTable;
import com.hh.clientdatatable.TCell.ValueType;
import com.hh.clientdatatable.TColumn;
import com.hh.ui.activity.UiActLeftSlidingMenu;

public class LeftSlidingMenuActivity extends UiActLeftSlidingMenu {


	private ClientDataTable _mCDT;
	private static String SELECTED_ITEM="SelectedItem";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentViewLeftMenu(R.layout.contentleftslidingmenu, 100);

		createCDT();
		fillCDT();
		
		CDTListAdapter lAdapter=new CDTListAdapter(this, R.layout.row_leftsliding_item, _mCDT){		
			@Override
			protected void onClickRow(View row, int position) {
				super.onClickRow(row, position);
				
				String lItem=_mCDT.cellByName("Item").asString();		
						
				sendData(1000, new Intent().putExtra(SELECTED_ITEM, lItem));
				closeSlidingMenu();
			}
		};

		lAdapter.setEnableOnClickWidget(false);

		ListView lList = (ListView) findViewById(R.id.mListItemsSlidingMenu);
		lList.setAdapter(lAdapter);

		/* used to set animation duration by default : speed animation when open =200 and when close = 150, we can change
		 * this value with this method :
		 * 
		 * setUpAnimationDuration(200, 100);
		 */
		
		// Set default orientation to PORTRAIT
		setScreenOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}

	private void createCDT(){

		_mCDT=new ClientDataTable(this);
		_mCDT.addColumn(new TColumn("Item", ValueType.TEXT));
		_mCDT.addColumn(new TColumn("Image", ValueType.INTEGER));
	}


	private void fillCDT(){

		String[] lItemsTab=getResources().getStringArray(R.array.ArrayHorizontalItems);
		int[] lItemsImage={R.drawable.ic_chrome,R.drawable.ic_facebook,R.drawable.ic_firefox,
				R.drawable.ic_googleplus,R.drawable.ic_internet,R.drawable.ic_maps,R.drawable.ic_message,R.drawable.ic_meto,
				R.drawable.ic_plaris,R.drawable.ic_skype,R.drawable.ic_tweeter};

		for (int i = 0; i < lItemsImage.length; i++) {
			
			_mCDT.append();
			_mCDT.cellByName("Item").setValue(lItemsTab[i]);
			_mCDT.cellByName("Image").setValue(lItemsImage[i]);
			_mCDT.commit();
		}
	}
}
